﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.Serialization;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

namespace CMS6Tools.Common.TFS
{
    [DataContract]
    public class Team
    {
        [DataMember]
        public TeamCapacity TeamCapacity { get; set; }

        [DataMember]
        public string[] ActivityValues { get; set; }

        [DataMember]
        public DateTime IterationStartDate { get; set; }

        [DataMember]
        public DateTime IterationEndDate { get; set; }

        [DataMember]
        public int[] Weekends { get; set; }

        [DataMember]
        public DateTime CurrentDate { get; set; }

        /// <summary>
        /// TFS 2015
        /// </summary>
        [DataMember]
        public bool IsMultipleActivityPerMemberSupported { get; set; }

        public void ConvertMultipleActivityToSingle()
        {
            if (IsMultipleActivityPerMemberSupported)
            {
                foreach (var teamMemberCapacity in TeamCapacity.TeamMemberCapacityCollection)
                {
                    if (teamMemberCapacity.Activities != null && teamMemberCapacity.Activities.Any())
                    {
                        teamMemberCapacity.Activity = teamMemberCapacity.Activities[0].Name;
                        teamMemberCapacity.Capacity = teamMemberCapacity.Activities[0].CapacityPerDay;
                    }

                    if (teamMemberCapacity.TeamMember != null)
                    {
                        teamMemberCapacity.DisplayName = Regex.Replace(teamMemberCapacity.TeamMember.DisplayName, @"\<[a-zA-Z 0-9\\]+\>", "", RegexOptions.IgnoreCase);
                        teamMemberCapacity.TeamMemberId = teamMemberCapacity.TeamMember.Id;
                    }

                    teamMemberCapacity.DaysOffDates = teamMemberCapacity.DaysOff;
                }
            }
        }
    }
}
